package main

import (
	"net"
	"fmt"
	"io"
)

func main() {
	tcpaddr, _ := net.ResolveTCPAddr("tcp4", ":9527")
	tcplistener, _ := net.ListenTCP("tcp4", tcpaddr)
	fmt.Println("正在连接，等待客户端接入")
	conn, err := tcplistener.Accept()
	fmt.Println(err)
	defer conn.Close()
	for {
		bs := make([]byte, 512)
		n, err := conn.Read(bs)
		fmt.Println(err,string(bs[:n]))
		if err == io.EOF||string(bs[:n])=="再见" {
			fmt.Println("客户端断开连接了,结束")
			break
		}
		fmt.Println("客户端", conn.RemoteAddr(), "说：", string(bs[:n]))
		conn.Write([]byte(string(bs[:n])))
	}

}
